package by.epam.trenings.vkphotorest.service.handlers.impl;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.ResultReceiver;
import by.epam.trenings.vkphotorest.service.ApplicationService;
import by.epam.trenings.vkphotorest.service.handlers.BaseHandler;

public class DbQueryHandler extends BaseHandler {

	@Override
	public void doExecute(final Intent intent, final Context context,
			final ResultReceiver callback) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				Uri uri = Uri.parse(intent
						.getStringExtra(ApplicationService.EXTRA_URI));
				String selection = intent
						.getStringExtra(ApplicationService.EXTRA_SELECTION);
				String[] selectionArgs = intent
						.getStringArrayExtra(ApplicationService.EXTRA_SELECTION_ARGS);
				String[] columns = intent
						.getStringArrayExtra(ApplicationService.EXTRA_COLUMNS);
				String sortOrder = intent
						.getStringExtra(ApplicationService.EXTRA_SORT_ORDER);
				context.getContentResolver().query(uri, columns, selection,
						selectionArgs, sortOrder);
				// Look for how put Cursor to bundle
				sendUpdate(SUCCESS_RESPONSE, new Bundle());
			}
		}).start();
	}

}
